package com.chuangxin.data.yuehengji;

import com.chuangxin.data.core.IDBasedFetcher;
import com.chuangxin.data.core.io.DataOutput;
import com.chuangxin.data.core.io.FileWriter;
import org.jsoup.nodes.Document;

import java.io.File;

/**
 * Created by Dawnwords on 2015/2/1.
 */
public class CYFetcher extends IDBasedFetcher {
    private static final int START_ID = 2;
    private static final int END_ID = 30678;
    private static final String URL_TEMPLATE = "http://www.yuehengji.com/chengyu/show.asp?id=${id}";

    public CYFetcher(DataOutput out) {
        super(out, START_ID, END_ID, URL_TEMPLATE);
    }

    @Override
    protected TitleContent processDoc(Document doc, String url) {
        String title = doc.select("div#container").select("div.title > h1").eq(0).html();
        String content = doc.select("div#sdcms_content").select("tbody").eq(0).html();
        return new TitleContent(title, content);
    }

    public static void main(String[] args) {
        new CYFetcher(new FileWriter("E:" + File.separator + "yuehengji" + File.separator + "chengyu")).execute();
    }
}
